package BestTimetoBuyandSellStock;

public class Solution {
    public int maxProfit(int[] prices) {
        int[] max=new int[prices.length+1];
        max[prices.length]=Integer.MIN_VALUE;
        for (int i=prices.length-1;i>=0;i--)
        	max[i]=Math.max(max[i+1], prices[i]);
        int result=0;
        max[prices.length]=Integer.MAX_VALUE;
        for (int i=0;i<prices.length;i++)
        	result=Math.max(result, max[i+1]-prices[i]);
        return result;
    }
}
